import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);

const router = new Router({
    routes: [{
            //首页
            path: '/',
            name: 'DefaultHome',
            component: () =>
                import ('@/pages/home/home'),
            redirect: "/home/index",
            meta: {
                title: '首页',
                isShowTabbar: true
            }
        },
        {
            //首页
            path: '/home',
            name: 'Home',
            component: () =>
                import ('@/pages/home/home'),
            meta: {
                title: '首页',
                isShowTabbar: true
            },
            children: [{
                    path: '',
                    redirect: "index"
                },
                {
                    path: 'index',
                    component: () =>
                        import ('@/pages/home/children/index'),
                    meta: {
                        title: '首页',
                        isShowTabbar: true
                    }
                },
                {
                    path: 'fashion',
                    component: () =>
                        import ('@/pages/home/children/fashion'),
                    meta: {
                        title: '时尚套装  ',
                        isShowTabbar: true
                    }
                },
                {
                    path: 'inexpensive',
                    component: () =>
                        import ('@/pages/home/children/inexpensive'),
                    meta: {
                        title: '捡漏专区',
                        isShowTabbar: true
                    }
                },
                {
                    path: 'popularityList',
                    component: () =>
                        import ('@/pages/home/children/popularityList'),
                    meta: {
                        title: '人气榜单',
                        isShowTabbar: true
                    }
                },
                {
                    path: 'recommend',
                    component: () =>
                        import ('@/pages/home/children/recommend'),
                    meta: {
                        title: '今日推荐',
                        isShowTabbar: true
                    }
                },
            ],
        },
        {
            // 分类
            path: '/classify',
            name: 'Classify',
            component: () =>
                import ('@/pages/classify/classify'),
            meta: {
                title: '分类',
                isShowTabbar: true
            },
        },
        {
            // 夜市
            path: '/nightMarket',
            name: 'NightMarket',
            component: () =>
                import ('@/pages/nightMarket/nightMarket'),
            meta: {
                title: '夜市',
                isShowTabbar: true
            }
        },
        {
            // 购物车
            path: '/shoppingCart',
            name: 'shoppingCart',
            component: () =>
                import ('@/pages/shoppingCart/shoppingCart'),
            meta: {
                title: '购物车',
                isShowTabbar: true
            }
        },
        {
            // 登录
            path: '/login',
            name: 'login',
            component: () =>
                import ('@/pages/login/login')
        },
        {
            path: '/loginpublic',
            name: 'loginpublic',
            component: () =>
                import ('@/pages/login/loginpublic')
        },
        {
            // 修改密码
            path: '/changePassword',
            name: 'changePassword',
            component: () =>
                import ('@/pages/login/changePassword')
        },
        {
            // 忘记密码
            path: '/forgetPassword',
            name: 'forgetPassword',
            component: () =>
                import ('@/pages/login/forgetPassword')
        },
        {
            // 注册
            path: '/register',
            name: ' register',
            component: () =>
                import ('@/pages/login/register')
        },
        {
            // 秒杀模块
            path: '/seckill',
            name: 'Seckill',
            component: () =>
                import ('@/pages/seckill/seckill'),
            meta: { title: "每日秒杀好物" },
            children: [
                // 二级路由
                { path: '', redirect: "seckilllist" },
                {
                    path: 'seckilllist',
                    component: () =>
                        import ('@/pages/seckill/seckilllist/seckilllist'),
                    meta: { title: "每日秒杀好物" }
                },
                {
                    path: 'tostartlist',
                    component: () =>
                        import ('@/pages/seckill/seckilllist/tostartlist'),
                    meta: { title: "每日秒杀好物" }
                },
            ]
        },
        {
            //  我的
            path: '/my',
            name: 'My',
            component: () =>
                import ('@/pages/my/my'),
            meta: {
                title: '我的',
                isShowTabbar: true
            }
        },

        {
            // 头部组件示例
            path: '/testHeader',
            name: 'TestHeader',
            component: () =>
                import ('@/components/myHeader/testHeader')
        },
        {
            // 底部组件示例
            path: '/testTabbar',
            name: 'TestTabbar',
            component: () =>
                import ('@/components/myTabbar/testTabbar')
        }, {
            // 商品列表示例
            path: '/testGoodList',
            name: 'TestGoodList',
            component: () =>
                import ('@/components/goodList/testGoodList')
        },
        {
            // 支付中心
            path: '/orderPay',
            name: 'orderPay',
            component: () =>
                import ('@/pages/order/orderPay'),
            meta: { title: "支付中心" },
        }, {
            // 商品详情
            path: '/goodDetail',
            name: 'GoodDetail',
            component: () =>
                import ('@/pages/good/goodDetail'),
            meta: { title: "商品详情" },
        },
        {
            // 订单确认
            path: '/orderComfirm',
            name: 'orderComfirm',
            component: () =>
                import ('@/pages/order/orderComfirm'),
            meta: { title: "订单确认" },
        },

        {
            // 分类
            path: '/classify',
            name: 'Classify',
            component: () =>
                import ('@/pages/classify/classify'),
            meta: {
                title: '分类',
                isShowTabbar: true
            },
        },
        {
            // 夜市
            path: '/nightMarket',
            name: 'NightMarket',
            component: () =>
                import ('@/pages/nightMarket/nightMarket'),
            meta: {
                title: '夜市',
                isShowTabbar: true
            }
        },
        {
            // 购物车
            path: '/shoppingCart',
            name: 'shoppingCart',
            component: () =>
                import ('@/pages/shoppingCart/shoppingCart'),
            meta: {
                title: '购物车',
                isShowTabbar: true
            }
        },
        {
            // 登录
            path: '/login',
            name: 'login',
            component: () =>
                import ('@/pages/login/login')
        },
        {
            path: '/loginpublic',
            name: 'loginpublic',
            component: () =>
                import ('@/pages/login/loginpublic')
        },
        {
            // 修改密码
            path: '/changePassword',
            name: 'changePassword',
            component: () =>
                import ('@/pages/login/changePassword')
        },
        {
            // 忘记密码
            path: '/forgetPassword',
            name: 'forgetPassword',
            component: () =>
                import ('@/pages/login/forgetPassword')
        },
        {
            // 注册
            path: '/register',
            name: ' register',
            component: () =>
                import ('@/pages/login/register')
        },
        {
            // 秒杀模块
            path: '/seckill',
            name: 'Seckill',
            component: () =>
                import ('@/pages/seckill/seckill'),
            meta: { title: "每日秒杀好物" },
            children: [
                // 二级路由
                { path: '', redirect: "seckilllist" },
                {
                    path: 'seckilllist',
                    component: () =>
                        import ('@/pages/seckill/seckilllist/seckilllist'),
                    meta: { title: "每日秒杀好物" }
                },
                {
                    path: 'tostartlist',
                    component: () =>
                        import ('@/pages/seckill/seckilllist/tostartlist'),
                    meta: { title: "每日秒杀好物" }
                },
            ]
        },
        {
            //  我的
            path: '/my',
            name: 'My',
            component: () =>
                import ('@/pages/my/my'),
            meta: {
                title: '我的',
                isShowTabbar: true
            }
        },
        {
            // 头部组件示例
            path: '/testHeader',
            name: 'TestHeader',
            component: () =>
                import ('@/components/myHeader/testHeader')
        },
        {
            // 底部组件示例
            path: '/testTabbar',
            name: 'TestTabbar',
            component: () =>
                import ('@/components/myTabbar/testTabbar')
        }, {
            // 商品列表示例
            path: '/testGoodList',
            name: 'TestGoodList',
            component: () =>
                import ('@/components/goodList/testGoodList')
        },
        {
            // 支付中心
            path: '/orderPay',
            name: 'orderPay',
            component: () =>
                import ('@/pages/order/orderPay'),
            meta: { title: "支付中心" },
        }, {
            // 商品详情
            path: '/goodDetail',
            name: 'GoodDetail',
            component: () =>
                import ('@/pages/good/goodDetail'),
            meta: { title: "商品详情" },
        },
        {
            // 订单确认
            path: '/orderComfirm',
            name: 'orderComfirm',
            component: () =>
                import ('@/pages/order/orderComfirm'),
            meta: { title: "订单确认" },
        },
        {
            // 优惠劵
            path: '/coupon',
            name: 'coupon',
            component: () =>
                import ('@/pages/coupon/coupon'),
            meta: { title: "优惠劵" },
        },
        {
            // 订单详情
            path: '/orderDetails',
            name: 'orderDetails',
            component: () => import('@/pages/order/orderDetails/orderDetails'),
            meta: { title: "订单详情" },
        },
        {
            // 订单列表
            path: '/orderList',
            name: 'orderList',
            component: () => import('@/pages/order/orderList/orderList'),
            meta: { title: "订单列表" },
            children:[
                {
                    // 全部订单
                    path: 'allOrders',
                    name:"allOrders",
                    component: () => import('@/pages/order/orderList/allOrders'),
                    meta: { title: "全部订单" }
                },
                {
                    // 待付款
                    path: 'awaitPayment',
                    name:"awaitPayment",
                    component: () => import('@/pages/order/orderList/awaitPayment'),
                    meta: { title: "待付款" }
                },
                {
                    // 待发货
                    path: 'awaitDeliver',
                    name:"awaitDeliver",
                    component: () => import('@/pages/order/orderList/awaitDeliver'),
                    meta: { title: "待发货" }
                },
                {
                    // 待收货
                    path: 'awaitReceiving',
                    name:"awaitReceiving",
                    component: () => import('@/pages/order/orderList/awaitReceiving'),
                    meta: { title: "待收货" }
                },
                {
                    // 已完成
                    path: 'orderFinish',
                    name:"orderFinish",
                    component: () => import('@/pages/order/orderList/orderFinish'),
                    meta: { title: "订单已完成" }
                },
                {path:"/orderList",redirect:"allOrders"}
            ]
        },

    ]
})

// 配置路由全局前置守卫
// const needLoginPaths = ['/coupon', '/orderList', '/orderDetails'];
router.beforeEach((to, from, next) => {
    // console.log('to.path', to.path);
    // if (!needLoginPaths.includes(to.path) || localStorage.getItem('telPhone')) {
    //     next();
    // } else {
    //     next({path: '/login'});
    // }
    // 改变页面标题
    document.title = to.meta.title ? to.meta.title : "穿衣有品";
    next();
});

export default router;
